import request from "@/utils/request";
import { useRoute, useRouter } from "vue-router";

const route = useRoute();
export function login(username, password, code, uuid) {
  const data = {
    name: username,
    password,
    code,
    uuid,
  };

  return request({
    url: "/user/login",
    method: "post",
    data: data,
  });
}
// 获取验证码图片
export function getCodeImg() {
  return request({
    url: "/captcha",
    method: "get",
    //  万恶之源  会将所有的返回值转换成arraybuffer类型    我找了2hours
    // responseType: "arraybuffer",
  });
}
//  发送邮箱验证码
export function sendEmailCode(email) {
  return request({
    url: "/captcha",
    method: "post",
    data: email,
  });
}

export function loginByEmail(email, ecode) {
  const data = {
    email,
    ecode,
  };
  return request({
    url: "/user/registeEmail",
    method: "post",
    data: data,
  });
}

export function register(username, password, repassword, email, ecode) {
  const data = {
    username,
    password,
    repassword,
    email,
    ecode,
  };
  return request({
    url: "/user/register",
    method: "post",
    data: data,
  });
}

// QQ登录
export function qqLogin(data) {
  return request({
    url: "/user/qqLogin",
    method: "post",
    params: {
      callbackUrl: route.query.redirectUrl || "",
    },
  });
}

// 重置密码
export function resetPassword(email, ecode, password, newpassword) {
  const data = {
    email,
    ecode,
    password,
    newpassword,
  };
  return request({
    url: "/user/resetPassword",
    method: "post",
    data: data,
  });
}

// 用户登出

export function loginOut() {
  return request({
    url: "/user/logout",
    method: "post",
  });
}
